﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Description;
using System.Text;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Discovery;

namespace XrmLibrary.Adapters
{
    public class DiscoveryServiceAdapter : ServiceAdapterBase<IDiscoveryService>, IDiscoveryServiceAdapter
    {
        private readonly DiscoveryServiceProxy _proxy;

        public DiscoveryServiceAdapter(IServiceConfiguration<IDiscoveryService> serviceConfiguration, ClientCredentials clientCredentials) : base(serviceConfiguration, clientCredentials)
        {
            _proxy = new DiscoveryServiceProxy(serviceConfiguration, clientCredentials);
        }

        public DiscoveryServiceAdapter(IServiceConfiguration<IDiscoveryService> serviceConfiguration, SecurityTokenResponse securityTokenResponse) : base(serviceConfiguration, securityTokenResponse)
        {
            _proxy = new DiscoveryServiceProxy(serviceConfiguration, securityTokenResponse);
        }

        public DiscoveryServiceAdapter(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials) : base(uri, homeRealmUri, clientCredentials, deviceCredentials)
        {
            _proxy = new DiscoveryServiceProxy(uri, homeRealmUri, clientCredentials, deviceCredentials);
        }

        public DiscoveryResponse Execute(DiscoveryRequest request)
        {
            return _proxy.Execute(request);
        }

        public DiscoveryServiceProxy GetDiscoveryServiceProxy()
        {
            return _proxy;
        }
    }
}
